package com.cskaoyan.controller;

import com.cskaoyan.bean.*;
import com.cskaoyan.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author WeitenHong
 * @date 2020/9/30 14:19
 */

@RestController
@RequestMapping("admin/")
public class AdminController {
    @Autowired
    UserService userService;


    @RequestMapping("dashboard")
    public BaseRespVo dashboard(){
        Subject subject = SecurityUtils.getSubject();
        System.out.println("admin/dashboard shiro验证:"+subject.isAuthenticated()+" sid："+subject.getSession().getId());

        DashBoard dashBoard=userService.getDashBoard();
        return BaseRespVo.ok(dashBoard);
    }

    @RequestMapping("address/list")
    public BaseRespVo list(String name, Integer userId, Integer page, Integer limit, String sort, String order){
        Subject subject = SecurityUtils.getSubject();
        System.out.println("address/list"+subject.getSession().getId());
        System.out.println(subject.isAuthenticated());

        ListBean listBean=userService.queryAddressListBean(name,userId,page,limit,sort,order);
        return BaseRespVo.ok(listBean);
    }

    @RequestMapping("collect/list")
    public BaseRespVo collectList(Integer userId, Integer valueId, Integer page, Integer limit, String sort, String order){
        CollectListBean collectListBean = userService.queryAdminCollectListBean(page,limit,sort,order,userId, valueId);
        return BaseRespVo.ok(collectListBean);
    }

    @RequestMapping("footprint/list")
    public BaseRespVo footprint(Integer page, Integer limit, Integer userId, Integer goodsId, String sort, String order){
        FootprintListBean footprintListBean = userService.queryFootprintListBean(page,limit,userId,goodsId,sort,order);
        return BaseRespVo.ok(footprintListBean);
    }

    //test
//    @RequestMapping("footprint/list")
//    public BaseRespVo footprint(Integer page, Integer limit, Integer userId, Integer goodsId, String sort, String order){
//        FootprintListBean footprintListBean = userService.queryFootprintListBean1(page, limit, userId, goodsId, sort, order);
//        return BaseRespVo.ok(footprintListBean);
//    }

    @RequestMapping("history/list")
    public BaseRespVo history(Integer page, Integer limit, Integer userId, String keyword, String sort, String order){
        SearchHistoryListBean searchHistoryListBean = userService.queryHistoryListBean(page, limit, keyword, userId, sort, order);
        return BaseRespVo.ok(searchHistoryListBean);
    }

    @RequestMapping("feedback/list")
    public BaseRespVo feedback(Integer page, Integer limit, Integer id, String username, String sort, String order){
        FeedbackListBean feedbackListBean = userService.queryFeedbackListBean(page, limit, id, username, sort, order);
        return BaseRespVo.ok(feedbackListBean);
    }



}
